package com.ruiyi.subway.utils;

import java.io.OutputStream;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class ViewExcel extends AbstractExcelView {  

	public Map<String, Object> map;
	public HSSFWorkbook book;
	public HttpServletRequest request;
	public HttpServletResponse response;

	@Override  
    protected void buildExcelDocument(Map<String, Object> map,  
            HSSFWorkbook book, HttpServletRequest request, HttpServletResponse response)  
            throws Exception {  
		this.map=map;
		this.book=book;
		this.request=request;
		this.response=response;
    }
	
	public static void buildExcelDocumentHaveFileName(Map<String, Object> map,  
            HSSFWorkbook book, HttpServletRequest request, HttpServletResponse response,String fileName)throws Exception{
		 response.setContentType("application/vnd.ms-excel");         
         response.setHeader("Content-disposition", "attachment;filename=" + java.net.URLEncoder.encode(fileName, "UTF-8"));         
         OutputStream ouputStream = response.getOutputStream();         
         book.write(ouputStream);         
         ouputStream.flush();         
         ouputStream.close(); 
		
	}


}  